# use bokeh to pic
# @Author: 赵彩霞

from math import pi
import pandas as pd
from bokeh.plotting import figure, show, output_file


class Bokeh:
    def __init__(self):
        pass

    def kline(self, df_):
        """K线图 df_: DataFrame"""
        df_["date"] = pd.to_datetime(df_["date"])
        inc = df_.close > df_.open
        dec = df_.open > df_.close
        w = 12 * 60 * 60 * 1000  # half day in ms
        TOOLS = "crosshair,pan,wheel_zoom,box_zoom,reset,save"
        p = figure(x_axis_type="datetime", tools=TOOLS, plot_width=1000, title="K线图")
        p.xaxis.major_label_orientation = pi / 4
        p.grid.grid_line_alpha = 0.3
        p.segment(df_.date, df_.high, df_.date, df_.low, color="black")
        p.vbar(df_.date[inc], w, df_.open[inc], df_.close[inc], fill_color="green", line_color="black")
        p.vbar(df_.date[dec], w, df_.open[dec], df_.close[dec], fill_color="red", line_color="black")
        output_file("candlestick.html", title="candlestick.py example")
        show(p)

